package org.truxingame.input;

import org.junit.Test;
import static org.junit.Assert.*;
import org.truxingame.PlayerIndex;

public class testGamePad {

	@Test
	public void testConnected() {
		GamePadState gamePad = GamePad.getState(PlayerIndex.One);
		assertTrue(gamePad.isConnected());
		if (gamePad.isConnected())
			System.out.println("Controller one is Connected");
		gamePad = GamePad.getState(PlayerIndex.Two);
		if (gamePad.isConnected())
			System.out.println("Controller two is Connected");
		gamePad = GamePad.getState(PlayerIndex.Three);
		if (gamePad.isConnected())
			System.out.println("Controller three is Connected");
		gamePad = GamePad.getState(PlayerIndex.Four);
		if (gamePad.isConnected())
			System.out.println("Controller four is Connected");
	}
	
	@Test
	public void testCapabilities() {
		GamePadCapabilities caps = GamePad.GetCapabilities(PlayerIndex.One);
		
		assertTrue(caps.getGamePadType() == GamePadType.GamePad);
		
		assertTrue(caps.IsConnected());
		
		assertTrue(caps.hasAButton());
		assertTrue(caps.hasBButton());
		assertTrue(caps.hasXButton());
		assertTrue(caps.hasYButton());
		
		assertTrue(caps.hasDPadDownButton());
		assertTrue(caps.hasDPadLeftButton());
		assertTrue(caps.hasDPadRightButton());
		assertTrue(caps.hasDPadUpButton());
		
		assertTrue(caps.hasLeftShoulderButton());
		assertTrue(caps.hasLeftStickButton());
		assertTrue(caps.hasLeftTrigger());
		assertTrue(caps.hasLeftVibrationMotor());
		assertTrue(caps.hasLeftXThumbStick());
		assertTrue(caps.hasLeftYThumbStick());
		assertTrue(caps.hasRightShoulderButton());
		assertTrue(caps.hasRightStickButton());
		assertTrue(caps.hasRightTrigger());
		assertTrue(caps.hasRightVibrationMotor());
		assertTrue(caps.hasRightXThumbStick());
		assertTrue(caps.hasRightYThumbStick());
		
		assertTrue(caps.hasVoiceSupport());
	}
	

	@Test
	public void testAnalogButtons() {
		GamePadState gamePad = GamePad.getState(PlayerIndex.One);

		System.out.println("Press Right Trigger");
		while(!gamePad.isButtonDown(new Buttons(Buttons.RightTrigger)))
			gamePad = GamePad.getState(PlayerIndex.One);
		
		System.out.println("Press Left Trigger");
		while(!gamePad.isButtonDown(new Buttons(Buttons.LeftTrigger)))
			gamePad = GamePad.getState(PlayerIndex.One);
		
		System.out.println("Press Both Triggers");
		while(!gamePad.isButtonDown(new Buttons(Buttons.LeftTrigger|Buttons.RightTrigger)))
			gamePad = GamePad.getState(PlayerIndex.One);
		
		System.out.println("Press Left Stick Left");
		while(!gamePad.isButtonDown(new Buttons(Buttons.LeftStickLeft)))
			gamePad = GamePad.getState(PlayerIndex.One);
		System.out.println("Press Left Stick Down");
		while(!gamePad.isButtonDown(new Buttons(Buttons.LeftStickDown)))
			gamePad = GamePad.getState(PlayerIndex.One);
		System.out.println("Press Left Stick Right");
		while(!gamePad.isButtonDown(new Buttons(Buttons.LeftStickRight)))
			gamePad = GamePad.getState(PlayerIndex.One);
		System.out.println("Press Left Stick Up");
		while(!gamePad.isButtonDown(new Buttons(Buttons.LeftStickUp)))
			gamePad = GamePad.getState(PlayerIndex.One);
		
		System.out.println("Press Right Stick Left");
		while(!gamePad.isButtonDown(new Buttons(Buttons.RightStickLeft)))
			gamePad = GamePad.getState(PlayerIndex.One);
		System.out.println("Press Right Stick Down");
		while(!gamePad.isButtonDown(new Buttons(Buttons.RightStickDown)))
			gamePad = GamePad.getState(PlayerIndex.One);
		System.out.println("Press Right Stick Right");
		while(!gamePad.isButtonDown(new Buttons(Buttons.RightStickRight)))
			gamePad = GamePad.getState(PlayerIndex.One);
		System.out.println("Press Right Stick Up");
		while(!gamePad.isButtonDown(new Buttons(Buttons.RightStickUp)))
			gamePad = GamePad.getState(PlayerIndex.One);
		
	}

	@Test
	public void testButtons() {
		GamePadState gamePad = GamePad.getState(PlayerIndex.One);

		System.out.println("Press A");
		while(gamePad.getButtons().getA() != ButtonState.Pressed)
			gamePad = GamePad.getState(PlayerIndex.One);

		System.out.println("Press B");
		while(gamePad.getButtons().getB() != ButtonState.Pressed)
			gamePad = GamePad.getState(PlayerIndex.One);

		System.out.println("Press X");
		while(gamePad.getButtons().getX() != ButtonState.Pressed)
			gamePad = GamePad.getState(PlayerIndex.One);

		System.out.println("Press Y");
		while(gamePad.getButtons().getY() != ButtonState.Pressed)
			gamePad = GamePad.getState(PlayerIndex.One);

		System.out.println("Press Back");
		while(gamePad.getButtons().getBack() != ButtonState.Pressed)
			gamePad = GamePad.getState(PlayerIndex.One);

		System.out.println("Press Start");
		while(gamePad.getButtons().getStart() != ButtonState.Pressed)
			gamePad = GamePad.getState(PlayerIndex.One);

		System.out.println("Press Left Shoulder");
		while(gamePad.getButtons().getLeftShoulder() != ButtonState.Pressed)
			gamePad = GamePad.getState(PlayerIndex.One);

		System.out.println("Press Right Shoulder");
		while(gamePad.getButtons().getRightShoulder() != ButtonState.Pressed)
			gamePad = GamePad.getState(PlayerIndex.One);

		System.out.println("Press Left Stick");
		while(gamePad.getButtons().getLeftStick() != ButtonState.Pressed)
			gamePad = GamePad.getState(PlayerIndex.One);

		System.out.println("Press Right Stick");
		while(gamePad.getButtons().getRightStick() != ButtonState.Pressed)
			gamePad = GamePad.getState(PlayerIndex.One);

	}

	@Test
	public void testTriggers() {
		GamePadState gamePad = GamePad.getState(PlayerIndex.One);

		System.out.println("Press Start - Press A to quit");
		while(gamePad.getButtons().getStart() != ButtonState.Pressed)
			gamePad = GamePad.getState(PlayerIndex.One);
		while(gamePad.getButtons().getA() != ButtonState.Pressed) {
			gamePad = GamePad.getState(PlayerIndex.One);
			System.out.print("\rLeft: ");
			System.out.print(gamePad.getTriggers().getLeft());

			System.out.print("\rRight: ");
			System.out.print(gamePad.getTriggers().getRight());

		}
	}

	@Test
	public void testThumbs() {
		GamePadState gamePad = GamePad.getState(PlayerIndex.One);

		System.out.println("Press Start - Press A to quit");
		while(gamePad.getButtons().getStart() != ButtonState.Pressed)
			gamePad = GamePad.getState(PlayerIndex.One);
		while(gamePad.getButtons().getA() != ButtonState.Pressed) {
			gamePad = GamePad.getState(PlayerIndex.One);
			System.out.print("\nLeft: ");
			System.out.print(gamePad.getThumbsticks().getLeft().getX());
			System.out.print(" : ");
			System.out.print(gamePad.getThumbsticks().getLeft().getY());

			System.out.print("\nRight: ");
			System.out.print(gamePad.getThumbsticks().getRight().getX());
			System.out.print(" : ");
			System.out.print(gamePad.getThumbsticks().getRight().getY());

		}
	}
	
	
	@Test
	public void testVibrarion() {
		GamePadState gamePad = GamePad.getState(PlayerIndex.One);

		System.out.println("Press Start - Press A to quit");
		while(gamePad.getButtons().getStart() != ButtonState.Pressed)
			gamePad = GamePad.getState(PlayerIndex.One);
		
		GamePad.SetVibration(PlayerIndex.One, 0.5f, 0.5f);
		System.out.println("Both - Press A");
		while(gamePad.getButtons().getA() != ButtonState.Pressed) {
			
			gamePad = GamePad.getState(PlayerIndex.One);
		}
		
		GamePad.SetVibration(PlayerIndex.One, 0.0f, 1.0f);
		System.out.println("Right - Press B");
		while(gamePad.getButtons().getB() != ButtonState.Pressed) {
			
			gamePad = GamePad.getState(PlayerIndex.One);
		}
		
		GamePad.SetVibration(PlayerIndex.One, 1.0f, 0.0f);
		System.out.println("Left - Press A");
		while(gamePad.getButtons().getA() != ButtonState.Pressed) {
			
			gamePad = GamePad.getState(PlayerIndex.One);
		}
		
		System.out.println("UseTriggers Press Start - Press A to end");
		while(gamePad.getButtons().getStart() != ButtonState.Pressed)
			gamePad = GamePad.getState(PlayerIndex.One);
		while(gamePad.getButtons().getA() != ButtonState.Pressed) {
			GamePad.SetVibration(PlayerIndex.One, gamePad.getTriggers().getLeft(), gamePad.getTriggers().getRight());	
			gamePad = GamePad.getState(PlayerIndex.One);
		}

	}
	
	
	
	
}
